home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACSHELL / MS1 / SHELL_SO / PATH.C < prev    next >
Text File  |  1992-12-02  |  21KB  |  1,051 lines

  1. /*
  2.  *    MacShell Source File
  3.  *
  4.  *    Copyright (c) 1989, 1990, 1991, 1992  Suick Bay Technologies.  All rights reserved.
  5.  *
  6.  *
  7.  *    RESTRICTIONS ON MacShell program and source code.
  8.  *
  9.  *    Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
  10.  *    restricted use by the owner of the CDROM "Disk to the future II".
  11.  *
  12.  *    Ñ╩No permission is granted for any commercial use without the written
  13.  *    consent of the Suick Bay Technologies.
  14.  *
  15.  *    Ñ╩No permission is granted for any redistribution of any kind use without
  16.  *    the written consent of the Suick Bay Technologies.
  17.  *
  18.  *    Ñ╩Permission is granted to use this for any personal noncommercial use.
  19.  *
  20.  *    Ñ╩You may not distribute source or executable code at all, nor may you 
  21.  *    distribute it with or within a commercial product without the written
  22.  *    consent of the Suick Bay Technologies.  Please send modifications to 
  23.  *    the author for inclusion in updates to the program.  Thanks.
  24.  *
  25.  *
  26.  *    MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  27.  *    WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  28.  *    PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  29.  *
  30.  *    SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  *    INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
  32.  *    OR ANY PART THEREOF. 
  33.  *
  34.  *    In no event will Suick Bay Technologies be liable for any lost revenue
  35.  *    or profits or other special, indirect and consequential damages, even if
  36.  *    Suick Bay Technologies has been advised of the possibility of such damages.
  37.  *
  38.  *    Suick Bay Technologies can be reached at:
  39.  *    
  40.  *    8768 Cottonwood lane
  41.  *    Maple Grove, MN 55369
  42.  *    Voice: (612) 425-7025
  43.  *    AppleLink: D5233
  44.  *    
  45.  *
  46.  *    No parts of this software may be reproduced or stored in a
  47.  *    retrieval system or transmitted in any form, or any means,
  48.  *    electronic, mechanical, photocopying, recording or otherwise,
  49.  *    without the prior written permission of Suick Bay Technologies.
  50.  *    
  51.  *    Spread the word and not the disk.
  52.  *    
  53.  *    SPK 030190    :    Update for Mac, DOS paths
  54.  *    SPK    012490    :    Fixed FindRoot to send Setvol a PString
  55.  *    SPK 012290    :    Initial
  56.  */
  57.  
  58. #include    <OSUtil.h>
  59.  
  60. #include    "System.h"
  61. #include    "Path.h"
  62. #include    "Prefs.h"
  63.  
  64. /*******************************************************************/
  65.  
  66. char    DirSep()
  67. {
  68. char    dirChar;
  69.  
  70.     if( ShellPrefs.useMacOSPath )
  71.         dirChar = ':';
  72.     else if( ShellPrefs.useUNIXPath )
  73.         dirChar = '/';
  74.     else if( ShellPrefs.useDOSPath )
  75.         dirChar = '\\';
  76.         
  77.     return( dirChar );
  78. }
  79.  
  80. /*******************************************************************/
  81.  
  82. Boolean        ResFileOpen( char *name, int16 vRefNum,
  83.                 int32 dirID, int16 *refNum )
  84. {
  85. HFileInfo    pb;
  86. OSErr        err;
  87. char        str[ 64 ];
  88.  
  89.     strcpy( str, name );
  90.     CtoPstr( str );
  91.  
  92.     pb.ioCompletion = NULL;
  93.     pb.ioNamePtr     = (StringPtr) str;
  94.     pb.ioVRefNum    = vRefNum;
  95.     pb.ioFDirIndex    = 0;
  96.     pb.ioDirID        = dirID;
  97.     
  98.     err = PBHGetFInfo( &pb, FALSE );
  99.     
  100.     if( err )
  101.         return( FALSE );
  102.     
  103.     else if( pb.ioFlAttrib & 0x04 )
  104.         {
  105.         *refNum = pb.ioFRefNum;
  106.         return( TRUE );
  107.         }
  108.     
  109.     return( FALSE );
  110. }
  111.  
  112. /*******************************************************************/
  113.  
  114. int16            ScanVols( char *pattern )
  115. {
  116. int16            i;
  117. HVolumeParam    HPB;
  118. char            str[ 64 ];
  119. OSErr            err;
  120.  
  121.     for(  i = 1; i < 10; i++ )
  122.         {
  123.         HPB.ioCompletion     = NULL;
  124.         HPB.ioNamePtr         = (StringPtr) str;
  125.         HPB.ioVRefNum         = 0;
  126.         HPB.ioVolIndex         = i;
  127.         
  128.         err = PBHGetVInfo( &HPB, FALSE );
  129.         
  130.         if( err == nsvErr )
  131.             break;
  132.             
  133.         if( err )
  134.             break;
  135.         else
  136.             {
  137.             PtoCstr( str );
  138.             if( StrPatMatch( str, pattern ) )
  139.                 return( HPB.ioVRefNum );
  140.             }
  141.         }
  142.         
  143.     return( 0 );
  144. }
  145.  
  146. /*******************************************************************/
  147.  
  148. OSErr         GetIndVolume( int16 whichVol, char *volName,
  149.                 int16 *volRefNum )
  150. {
  151. HVolumeParam    volPB;
  152. OSErr             error;
  153.  
  154.     volPB.ioNamePtr = (StringPtr) volName;
  155.     volPB.ioVRefNum = 0;
  156.     volPB.ioVolIndex = whichVol;
  157.  
  158.     error = PBHGetVInfo(&volPB,false); 
  159.     if( error == noErr )  
  160.         *volRefNum = volPB.ioVRefNum;
  161.  
  162.     return(error);
  163. }
  164.  
  165. /*******************************************************************
  166.  *    Convert a Mac Pathname to a UNIX pathname
  167.  *******************************************************************/
  168.  
  169. Boolean        isMacName( char c )
  170. {
  171.     return( isPrint( c ) && c != ':' );
  172. }
  173.  
  174. void        _MacToUNIXPath( char *path )
  175. {
  176. char        tpath[ 256 ], *cp, *tp;
  177. Boolean        subDirs = FALSE, fullPath = FALSE;
  178.  
  179.     cp = path;
  180.     tp = tpath;
  181.     
  182.     if( *cp == ':' )    /* partial pathname */
  183.         *cp++;
  184.     else
  185.         {
  186.         *tp++ = '/';
  187.         *tp++ = '/';
  188.         fullPath = TRUE;
  189.         }
  190.     
  191.     while( *cp )
  192.         {
  193.         while( isMacName( *cp ) )
  194.             *tp++ = *cp++;
  195.     
  196.         if( *cp == ':' )    /* convert dir */
  197.             {
  198.             if( *(cp+1) )    /* not end of path */
  199.                 *tp++ = '/';
  200.             *cp++;
  201.             }
  202.         else    /* some weird character */
  203.             *tp++ = *cp++;
  204.         }
  205.  
  206.     *tp = *cp;
  207.     strcpy( path, tpath );
  208. }
  209.  
  210. void        _MacToDOSPath( char *path )
  211. {
  212. char        tpath[ 256 ], *cp, *tp;
  213. Boolean        subDirs = FALSE, fullPath = FALSE;
  214.  
  215.     cp = path;
  216.     tp = tpath;
  217.     
  218.     if( *cp == ':' )    /* partial pathname */
  219.         *cp++;
  220.     else                /* full path */
  221.         {
  222.         while( (*cp != ':') && *cp )    /* copy vol name */
  223.             *tp++ = *cp++;
  224.  
  225.         if( *cp )
  226.             {
  227.             *tp++ = *cp++;
  228.             *tp++ = '\\';
  229.             }
  230.         else
  231.             {
  232.             *tp++ = ':';
  233.             *tp++ = '\\';
  234.             *tp = '\0';
  235.             }
  236.         }
  237.     
  238.     while( *cp )
  239.         {
  240.         while( isMacName( *cp ) )
  241.             *tp++ = *cp++;
  242.     
  243.         if( *cp == ':' )    /* convert dir */
  244.             {
  245.             if( *(cp+1) )    /* not end of path */
  246.                 *tp++ = '\\';
  247.             *cp++;
  248.             }
  249.         else    /* some weird character */
  250.             *tp++ = *cp++;
  251.         }
  252.  
  253.     *tp = *cp;
  254.     strcpy( path, tpath );
  255. }
  256.  
  257. void        _MacToMacPath( char *path )
  258. {
  259. char        tpath[ 256 ], *cp, *tp;
  260.  
  261.     cp = path;
  262.     tp = tpath;
  263.  
  264. #ifdef    FALSE    
  265.     if( *cp == ':' )    /* partial pathname */
  266.         *cp++;
  267.     
  268.     while( *cp )
  269.         {
  270.         if( *cp == ':' )    /* path */
  271.             break;
  272.         cp++;
  273.         }
  274. #endif
  275.  
  276.     if( *cp == ':' )    /* in this dir */
  277.         {
  278.         cp = path;
  279.         cp++;
  280.         strcpy( tpath, cp );
  281.         strcpy( path, tpath );
  282.         }
  283. }
  284.  
  285. void    MacToPath( char *path )
  286. {
  287.     if( ShellPrefs.useMacOSPath )
  288.         _MacToMacPath( path );
  289.     else if( ShellPrefs.useUNIXPath )
  290.         _MacToUNIXPath( path );
  291.     else if( ShellPrefs.useDOSPath )
  292.         _MacToDOSPath( path );
  293. }
  294.  
  295. /*******************************************************************/
  296.  
  297. char    scanPath[ 256 ];
  298. char    lastScan[ 64 ];
  299.  
  300. pathType    ScanDir( char *lookFor, int16 *vRefNum, int32 *dirID, int32 *parDirID )
  301. {
  302. int16        i, numEntries;
  303. OSErr        err;
  304. CInfoPBRec    localPB;
  305.  
  306. /*
  307.  *    Get the number of items in this directory
  308.  */
  309.     localPB.dirInfo.ioFDirIndex     = -1;    /* this directory */
  310.     localPB.dirInfo.ioCompletion = NULL; 
  311.     localPB.dirInfo.ioNamePtr    = NULL;
  312.     localPB.dirInfo.ioVRefNum     = *vRefNum;
  313.     localPB.dirInfo.ioDrDirID    = *dirID;
  314.     
  315.     err = PBGetCatInfo( &localPB, FALSE );
  316.     
  317.     numEntries = localPB.dirInfo.ioDrNmFls;
  318. /*
  319. printf( "scan dir for %s vref %d dirID %ld\n",
  320.     lookFor, *vRefNum, *dirID );
  321. */
  322.     for(i = 1; i <= numEntries; i++)
  323.         {
  324.         localPB.hFileInfo.ioFDirIndex     = i;
  325.         localPB.hFileInfo.ioCompletion     = NULL; 
  326.         localPB.hFileInfo.ioNamePtr        = (StringPtr) lastScan;
  327.         localPB.hFileInfo.ioVRefNum     = *vRefNum;
  328.         localPB.hFileInfo.ioDirID        = *dirID;
  329.         
  330.         err = PBGetCatInfo(  &localPB, FALSE);
  331. /*
  332. printf( "    %3d : %ps\n", i, lastScan );
  333. */
  334.         if( err == fnfErr )
  335.             break;
  336.  
  337.         if( err || UserAbort() )
  338.             break;
  339.  
  340.         PtoCstr( lastScan );
  341.         if( StrPatMatch( lastScan, lookFor ) )
  342.             {
  343.             if( localPB.hFileInfo.ioFlAttrib & 0x10 )
  344.                 {
  345.                 *dirID    = localPB.hFileInfo.ioDirID;
  346.                 return( pathIsDir );
  347.                 }
  348.             else
  349.                 return( pathIsFile );
  350.             }
  351.         }
  352.     
  353.     return( pathDNExist );
  354. }
  355.  
  356. /*******************************************************************/
  357.  
  358. void        GetDirSize( char *path, int16 vRefNum, int32 dirID, int32 *size )
  359. {
  360. int16        i, numEntries;
  361. OSErr        err;
  362. CInfoPBRec    localPB;
  363. char        str[ 256 ];
  364. /*
  365.  *    Get the number of items in this directory
  366.  */
  367.     localPB.dirInfo.ioFDirIndex     = 0;    /* this directory */
  368.     localPB.dirInfo.ioCompletion = NULL; 
  369.     localPB.dirInfo.ioNamePtr    = (StringPtr) path;
  370.     localPB.dirInfo.ioVRefNum     = vRefNum;
  371.     localPB.dirInfo.ioDrDirID    = dirID;
  372.     
  373.     err = PBGetCatInfo( &localPB, FALSE );
  374.     
  375.     numEntries = localPB.dirInfo.ioDrNmFls;
  376.     dirID = localPB.dirInfo.ioDrDirID;
  377.  
  378.     for( i = 1; i<= numEntries; i++ )
  379.         {
  380.         if( UserAbort() )
  381.             break;
  382.         
  383.         localPB.hFileInfo.ioFDirIndex     = i;
  384.         localPB.hFileInfo.ioCompletion     = NULL; 
  385.         localPB.hFileInfo.ioNamePtr        = (StringPtr) path;
  386.         localPB.hFileInfo.ioVRefNum     = vRefNum;
  387.         localPB.hFileInfo.ioDirID        = dirID;
  388.         
  389.         err = PBGetCatInfo(  &localPB, FALSE);
  390.  
  391.         if( err )
  392.             break;
  393.  
  394.         if( localPB.hFileInfo.ioFlAttrib & 0x10 )
  395.             GetDirSize(  path, vRefNum, localPB.hFileInfo.ioDirID, size );
  396.         else
  397.             *size += localPB.hFileInfo.ioFlLgLen + localPB.hFileInfo.ioFlRLgLen;
  398.         }
  399. }
  400.  
  401. /*******************************************************************/
  402.  
  403. OSErr    GetParID( int16 vRefNum, int32 dirID, int32 *parDirID )
  404. {
  405. CInfoPBRec        localPB;
  406. OSErr            err;
  407.  
  408.     localPB.hFileInfo.ioCompletion     = NULL;
  409.     localPB.hFileInfo.ioResult         = 0;
  410.     localPB.hFileInfo.ioNamePtr        = 0;
  411.     localPB.hFileInfo.ioVRefNum     = vRefNum;
  412.     localPB.hFileInfo.ioFDirIndex    =-1;
  413.     localPB.hFileInfo.ioDirID        = dirID;
  414.  
  415.     err = PBGetCatInfo (&localPB ,FALSE);
  416.     *parDirID = localPB.hFileInfo.ioFlParID;
  417.     
  418.     return( err );
  419. }
  420.  
  421. OSErr    GetDirName( int16 vRefNum, int32 dirID, char *name )
  422. {
  423. CInfoPBRec        localPB;
  424. OSErr            err;
  425.  
  426.     localPB.hFileInfo.ioCompletion     = NULL;
  427.     localPB.hFileInfo.ioResult         = 0;
  428.     localPB.hFileInfo.ioNamePtr        = (StringPtr) name;
  429.     localPB.hFileInfo.ioVRefNum     = vRefNum;
  430.     localPB.hFileInfo.ioFDirIndex    = -1;
  431.     localPB.hFileInfo.ioDirID        = dirID;
  432.  
  433.     err = PBGetCatInfo (&localPB ,FALSE);
  434.     return( err );
  435. }
  436.  
  437. /*******************************************************************
  438.  *    Get information about the current directory
  439.  *
  440.  *    Volume Ref Number
  441.  *    Directory ID
  442.  *    Parent Dir ID
  443.  *******************************************************************/
  444.  
  445. OSErr            GetPWDInfo( int16 *vRefNum, int32 *dirID, int32 *parDirID )
  446. {
  447. OSErr            err;
  448. CInfoPBRec        localPB;
  449. char             str[ 64 ];
  450.  
  451.     err = HGetVol( str, vRefNum, dirID );
  452.  
  453.     if( err == noErr )
  454.         {
  455.         localPB.hFileInfo.ioCompletion     = NULL;
  456.         localPB.hFileInfo.ioResult         = 0;
  457.         localPB.hFileInfo.ioNamePtr        = 0;
  458.         localPB.hFileInfo.ioVRefNum     = *vRefNum;
  459.         localPB.hFileInfo.ioFDirIndex    =-1;
  460.         localPB.hFileInfo.ioDirID        = *dirID;
  461.     
  462.         err = PBGetCatInfo (&localPB ,FALSE);
  463.     
  464.         *parDirID    =    localPB.hFileInfo.ioFlParID;
  465.         }
  466.         
  467. #ifdef    RDB
  468.     printf( "GetPWDInfo vRefNum %d dirID %ld parDirID %ld\n",
  469.         *vRefNum, *dirID, *parDirID );
  470. #endif
  471.     return( err );
  472. }
  473.  
  474. /*******************************************************************/
  475.  
  476. OSErr        SetWD( int16 vRefNum, int32 dirID )
  477. {
  478. OSErr        err;
  479.  
  480. #ifdef    RDB
  481.     printf( "SetWD vRefNum %d dirID %ld\n",
  482.         vRefNum, dirID );
  483. #endif
  484.  
  485.     err = HSetVol( NULL, vRefNum, dirID );
  486.     return( err );
  487. }
  488.  
  489. /*******************************************************************
  490.  *
  491.  *    This function moves through a path name looking for the
  492.  *    end of the path, it returns what it found, if it found it.
  493.  *    
  494.  *******************************************************************/
  495.  
  496. pathType     SetDirPath( char *path, int16 *vRefNum, int32 *dirID,
  497.                 int32 *parDirID )
  498. {
  499. char         buf[256];
  500. int16         i=0;
  501. pathType     pt;
  502. OSErr        err;
  503.  
  504.     if( *path == '\0' )
  505.         return( pathIsDir );
  506.                 
  507.     if( *path == ':')
  508.         {
  509.         if( *(path+1) == ':' )    
  510.             while( *path == ':' && *(path+1) == ':' )
  511.                 {
  512.                 SetWD( *vRefNum, *parDirID );
  513.                 GetPWDInfo( vRefNum, dirID, parDirID );
  514.                 path++;    
  515.                 path++;    
  516.                 }
  517.         else
  518.             path++;
  519.         }
  520.     else 
  521.         return( pathDNExist );
  522.  
  523.     if( *path =='\0')
  524.         return( pathIsDir );
  525.         
  526.     while( (*path != ':') && *path)
  527.         buf[i++] = *path++;
  528.         
  529.     buf[i] = '\0';
  530.     
  531.     pt = ScanDir( buf, vRefNum, dirID, parDirID );
  532.     
  533.     switch( pt )
  534.         {
  535.         case    pathDNExist    :
  536.             break;
  537.             
  538.         case    pathIsFile     :
  539.             break;
  540.             
  541.         case    pathIsDir    :
  542.             SetWD( *vRefNum, *dirID );
  543.             break;
  544.         }
  545.     
  546.     if( *path =='\0')
  547.         return( pt );
  548.     else 
  549.         return( SetDirPath( path, vRefNum, dirID, parDirID ) );
  550. }
  551.  
  552. /*******************************************************************/
  553.  
  554. void    _UNIXToMac( char *path, Boolean *neededVol, Boolean *goToRoot,
  555.             char *volName )
  556. {
  557. char     buf[256],             /* buffer for storing dir names */
  558.         *dirbuf[ MAX_DIR ], /* pointers to directory names    */
  559.         *cp,                 /* temp pointer */
  560.         *pathBase;            /* temp pointer */
  561.         
  562. int16     i = 0,
  563.         d = 0,
  564.         root = 0,
  565.         c = 0;
  566.  
  567.     pathBase = cp = path;
  568.     *neededVol = FALSE;
  569.     *goToRoot = FALSE;
  570.  
  571.     while( *cp == '/')    /* look for root and volume spec */
  572.         {
  573.         cp++;        /* root=0 then partial path     */
  574.         root++;        /* root=1 then full pathname     */
  575.         }            /* root=2 then vol specifier    */
  576.  
  577.     while ( *cp )    /* look for directories */
  578.         {
  579.         while( *cp == '/')    /* ??? Dan Code */
  580.             cp++;
  581.             
  582.         if( *cp )
  583.             {
  584.             dirbuf[ d ] = &(buf[ i ]);
  585.             
  586.             while ( *cp && (*cp != '/'))
  587.                 {
  588.                 if( *cp == '\\')
  589.                     {
  590.                     buf[ i++ ] = *cp++;
  591.                     break;
  592.                     }
  593.                 else
  594.                     buf[ i++ ] = *cp++;
  595.                 }
  596.     
  597.             buf[ i++ ] = '\0';
  598.             d++;
  599.             
  600.             if( d > MAX_DIR )
  601.                 break;
  602.             }    /* End if    */
  603.         }        /* End while ( *cp) */
  604.         
  605.     switch( root )
  606.         {
  607.         case    0    :    /* partial */
  608.             *path++ = ':';
  609.             break;
  610.             
  611.         case    1    :    /* root dir */
  612.             *goToRoot = TRUE;
  613.             if (d > 0) 
  614.                 *path++=':';    
  615.             break;
  616.             
  617.         case    2    :    /* volume    */
  618.             *neededVol = TRUE;
  619.             if( d > 1 ) 
  620.                 {
  621.                 c = 1;
  622.                 *path++=':';
  623.                 }
  624.             else if( d == 1 )
  625.                 {
  626.                 c = 1;
  627.                 *path = '\0';
  628.                 }
  629.             break;
  630.         }
  631.         
  632.     if( *neededVol && ( d < 1 ))
  633.         {
  634.         *path = '\0';
  635.         
  636.         }
  637.     else
  638.         {    
  639.         for( i = c; i < d; i++ )
  640.             {
  641. #ifdef MYDEBUG
  642.             printf( "%d    '%s'\n", i, dirbuf[i] );
  643. #endif
  644.             if( (strcmp(dirbuf[i], "..") == 0)) 
  645.                 *path++ = ':';
  646.             else if ( strcmp( dirbuf[i], "\\") == 0) 
  647.                 {
  648.                 *path++ = ':';
  649.                 if( i>0 )
  650.                     *path++ = ':';
  651.                 }
  652.             else if( strcmp(dirbuf[i], ".") == 0)
  653.                 continue;         
  654.             else
  655.                 {
  656.                 cp = dirbuf[i];
  657.                 while( *path++ = *cp++ );
  658.                 path--;
  659.                 if( i< (d-1) )
  660.                     *path++=':';
  661.                 }
  662.             }
  663.             
  664.         *path++ = '\0';
  665. #ifdef MYDEBUG
  666.         printf("The current path name is %s\n",pathBase);
  667. #endif        
  668.         if( *neededVol )
  669.             strcpy( volName, dirbuf[ 0 ] );
  670.         }
  671. }
  672.  
  673.  
  674. void    _DOSToMac( char *path, Boolean *neededVol, Boolean *goToRoot,
  675.             char *volName )
  676. {
  677. char     buf[256],             /* buffer for storing dir names */
  678.         *dirbuf[ MAX_DIR ], /* pointers to directory names    */
  679.         *cp,                 /* temp pointer */
  680.         *pathBase;            /* temp pointer */
  681.         
  682. int16     i = 0,
  683.         d = 0,
  684.         partial = FALSE,
  685.         c = 0;
  686.  
  687.     pathBase = cp = path;
  688.     *neededVol = FALSE;
  689.     *goToRoot = FALSE;
  690.  
  691.  
  692. /*
  693.  *        Dave:                volume
  694.  *        Dave:\blah\blab        full path
  695.  *        \blah\blab            full path
  696.  *        blah                dir
  697.  *        blah\blab            partial path
  698.  *        blab                file
  699.  */
  700.     
  701.     if( *cp == '\\')
  702.         {
  703.         cp++;
  704.         *goToRoot = TRUE;
  705.         partial = TRUE;
  706.         }
  707.     else            /* could be a volume */
  708.         {
  709.         char    *vp, *save;
  710.         
  711.         save = cp;
  712.         vp = volName;
  713.         while( (*cp != '\\') && (*cp != ':') && *cp )
  714.             *vp++ = *cp++;
  715.             
  716.         if( *cp == ':' )    /* found volume */
  717.             {
  718.             *vp = '\0';
  719.             *neededVol = TRUE;
  720.             }
  721.             
  722.         /* partial path */
  723.         cp = save;
  724.         partial = TRUE;
  725.         }
  726.  
  727.     while( *cp )
  728.         {
  729.         while( *cp == '\\')
  730.             cp++;
  731.             
  732.         if( *cp )
  733.             {
  734.             dirbuf[ d ] = &(buf[ i ]);
  735.             
  736.             while ( *cp && (*cp != '\\'))
  737.                 {
  738.                 if( *cp == '\\')        /* dir specifier */
  739.                     {
  740.                     buf[ i++ ] = *cp++;
  741.                     break;
  742.                     }
  743.                 else if( *cp == ':' )    /* volume spec */
  744.                     {
  745.                     cp++;    /* yooo here */
  746.                     }
  747.                 else
  748.                     buf[ i++ ] = *cp++;
  749.                 }
  750.     
  751.             buf[ i++ ] = '\0';
  752.             d++;
  753.             
  754.             if( d > MAX_DIR )
  755.                 break;
  756.             }    /* End if    */
  757.         }        /* End while ( *cp) */
  758.         
  759.     if( *neededVol && ( d < 1 ))
  760.         {
  761.         *path = '\0';
  762.         }
  763.     else
  764.         {
  765.         if( partial )
  766.             *path++ = ':';
  767.         
  768.         for( i = c; i < d; i++ )
  769.             {
  770.             if( (strcmp(dirbuf[i], "..") == 0)) 
  771.                 *path++ = ':';
  772.             else if ( strcmp( dirbuf[i], "\\") == 0) 
  773.                 {
  774.                 *path++ = ':';
  775.                 if( i>0 )
  776.                     *path++ = ':';
  777.                 }
  778.             else if( strcmp(dirbuf[i], ".") == 0)
  779.                 continue;         
  780.             else
  781.                 {
  782.                 cp = dirbuf[i];
  783.                 while( *path++ = *cp++ );
  784.                 path--;
  785.                 if( i< (d-1) )
  786.                     *path++=':';
  787.                 }
  788.             }
  789.             
  790.         *path++ = '\0';
  791.         }
  792. }
  793.  
  794. void    _MacToMac( char *path, Boolean *neededVol, Boolean *goToRoot,
  795.             char *volName )
  796. {
  797. char     *cp, *vp;
  798.         
  799.     cp = path;
  800.     *neededVol = FALSE;
  801.     *goToRoot = FALSE;
  802.  
  803.     if( *cp != ':' )    /* file or full pathname */
  804.         {
  805.         while( *cp )
  806.             {
  807.             if( *cp == ':' )
  808.                 break;
  809.             cp++;
  810.             }
  811.             
  812.         if( *cp == ':' )    /* full path */
  813.             {
  814.             cp = path;
  815.             vp = volName;
  816.             while( (*cp != ':') && *cp )    /* vol name */
  817.                 *vp++ = *cp++;
  818.  
  819.             *vp = '\0';
  820.             if( *cp )        /* copy : and path */
  821.                 {
  822.                 vp = path;
  823.                 while( *cp )
  824.                     *vp++ = *cp++;
  825.                 *vp = '\0';
  826.                 }
  827.                 
  828.             *neededVol = TRUE;
  829.             }
  830.         else                /* file */
  831.             {
  832.             char buf[ 256 ];
  833.             
  834.             strcpy( buf, path );
  835.             strcpy( path, ":" );
  836.             strcat( path, buf );
  837.             }
  838.         }
  839. }
  840.  
  841. /********************************************************************/
  842.  
  843. Boolean        FindRoot()
  844. {
  845. OSErr        err;
  846. char        buf[ 255 ];
  847. char        name[ 64 ], *cp;
  848. int16        i=0;
  849. int16        MyVolRefNum, newVolRefNum;
  850.  
  851.     GetCurrPath( buf );
  852.     cp = buf;
  853.     
  854.     while( *cp == '/' )
  855.         cp++;
  856.  
  857.     while ( *cp && (*cp != '/'))
  858.         name[ i++ ] = *cp++;
  859.         
  860.     name[ i++ ] = '\0';
  861.     cp = name;
  862.     i=1;
  863.     newVolRefNum = 0;
  864.     
  865.     while ( GetIndVolume(i++, buf , &MyVolRefNum) != nsvErr )
  866.         { 
  867.         PtoCstr( buf );
  868.         if( strcmp( buf , name ) == 0 )
  869.             newVolRefNum = MyVolRefNum;
  870.         }
  871.         
  872.     CtoPstr( name );
  873.     err = SetVol( (StringPtr) cp, newVolRefNum );
  874.     
  875.     if( err )
  876.         return ( FALSE );
  877.     else
  878.         return( TRUE );
  879. }
  880.  
  881. /*******************************************************************
  882.  *    
  883.  *******************************************************************/
  884.  
  885. Boolean        ChangeVol( char *newVolName )
  886. {
  887. int16        vRefNum, err;
  888. WDPBRec        WDR;
  889.  
  890. #ifdef MYDEBUG
  891.     printf("Entered Change Vol\n");
  892. #endif
  893.  
  894.     vRefNum = ScanVols( newVolName );
  895.     
  896.     if( vRefNum )
  897.         {
  898.         err = SetVol( NULL, vRefNum );
  899.         
  900.         if( !err )
  901.             return( TRUE );
  902.         }
  903.         
  904.     return( FALSE );
  905. }
  906.  
  907. /*******************************************************************
  908.  *    Set the current path
  909.  *    If the unix flag is true then the path is a
  910.  *    UNIX path, else it is a Mac path
  911.  *    return any OsErr.
  912.  *******************************************************************/
  913.  
  914. pathType    SetCurrPath( char *path )
  915. {
  916. int16         vRefNum;
  917. int32        dirID, parDirID;
  918. char        newVolName[ 64 ], buf[ 256 ];
  919. Boolean        neededVol,goToRoot,foundLastDir;
  920.  
  921. #ifdef RDB
  922.     GetPWDInfo( &vRefNum, &dirID, &parDirID );
  923.     printf( "SetCurrPath vRef %d dirID %ld START\n", vRefNum, dirID );
  924. #endif
  925.  
  926.     scanPath[ 0 ] = '\0';
  927.     strcpy( buf, path );
  928.     
  929.     if( ShellPrefs.useMacOSPath )
  930.         _MacToMac( buf, &neededVol, &goToRoot, newVolName );
  931.     else if( ShellPrefs.useUNIXPath )
  932.         _UNIXToMac( buf, &neededVol, &goToRoot, newVolName );
  933.     else if( ShellPrefs.useDOSPath )
  934.         _DOSToMac( buf, &neededVol, &goToRoot, newVolName );
  935.  
  936.     if( goToRoot )
  937.         {
  938.         if( FindRoot() )
  939.             {
  940.             GetPWDInfo( &vRefNum, &dirID, &parDirID );
  941.             return( SetDirPath( buf, &vRefNum, &dirID, &parDirID) );            
  942.             }
  943.         }
  944.         
  945.     GetPWDInfo( &vRefNum, &dirID, &parDirID );
  946.     
  947. #ifdef RDB
  948.     printf( "SetCurrPath vRef %d dirID %ld\n", vRefNum, dirID );
  949. #endif
  950.     
  951.     if( neededVol )
  952.         {
  953.         if( ChangeVol( newVolName ) == FALSE )    /* no volume */
  954.             return( nsvErr );
  955.             
  956.         GetPWDInfo( &vRefNum, &dirID, &parDirID );
  957.         }
  958.         
  959.     return( SetDirPath( buf, &vRefNum, &dirID, &parDirID) );
  960. }
  961.  
  962.  
  963. /*******************************************************************
  964.  *    Get the current path
  965.  *     if unix flag is TRUE then return UNIX path
  966.  *    else return Mac pathname
  967.  *******************************************************************/
  968.  
  969. OsErr        GetMacPathFrom( int16 vRefNum, int32 dirID, char *buf )
  970. {
  971. char        temp[ 256 ];
  972. char        path[ 256 ], *cp;
  973. int32         parDirID;
  974. CInfoPBRec    localPB;
  975. int16        i = 0, err, j;
  976.  
  977.     
  978.     localPB.hFileInfo.ioCompletion         = NULL;
  979.     localPB.hFileInfo.ioNamePtr         = (StringPtr) buf;    
  980.     localPB.hFileInfo.ioVRefNum         = vRefNum;
  981.     localPB.hFileInfo.ioDirID            = dirID;
  982.     localPB.hFileInfo.ioFDirIndex         = -1;
  983.     localPB.hFileInfo.ioResult            = 0;
  984.     strcpy( path, "" );
  985.  
  986.     while( !localPB.hFileInfo.ioResult )
  987.         {
  988.         localPB.hFileInfo.ioCompletion = NULL;
  989.  
  990.         PBGetCatInfo( &localPB, FALSE );
  991.         if( localPB.hFileInfo.ioResult == fnfErr )
  992.             break;
  993.             
  994.         PtoCstr( buf );
  995.         if( i > 0 )
  996.             strcat( buf, ":" );
  997.             
  998.         strcat( buf, path );
  999.         strcpy( path, buf );
  1000.         
  1001.         localPB.hFileInfo.ioDirID = localPB.hFileInfo.ioFlParID;
  1002.         localPB.hFileInfo.ioFDirIndex = -1;
  1003.         i++;
  1004.         }
  1005.     
  1006.     strcpy( buf, path );
  1007.  
  1008.     if( localPB.hFileInfo.ioResult != fnfErr )
  1009.         return( localPB.hFileInfo.ioResult );
  1010.     else
  1011.         return( noErr );
  1012. }
  1013.  
  1014. /*******************************************************************/
  1015.  
  1016. OsErr        GetPathFrom( int16 vRefNum, int32 dirID, char *buf )
  1017. {
  1018. OsErr err;
  1019.  
  1020.     err = GetMacPathFrom( vRefNum, dirID, buf );
  1021.     MacToPath( buf );
  1022.     return( err );
  1023. }
  1024.  
  1025. OsErr        GetCurrPath( char *buf )
  1026. {
  1027. int16        vRefNum, err;
  1028. int32         dirID, parDirID;
  1029.  
  1030.     GetPWDInfo( &vRefNum, &dirID, &parDirID );
  1031.     err = GetPathFrom( vRefNum, dirID, buf );
  1032.     return( err );
  1033. }
  1034.  
  1035. OsErr        GetCurrMacPath( char *buf  )
  1036. {
  1037. int16        vRefNum;
  1038. int32         dirID, parDirID;
  1039.  
  1040.     GetPWDInfo( &vRefNum, &dirID, &parDirID );
  1041.     return( GetMacPathFrom( vRefNum, dirID, buf ) );
  1042. }
  1043.  
  1044. /*******************************************************************/
  1045.  
  1046. char    *GetLastScan()
  1047. {
  1048.     return( lastScan );
  1049. }
  1050.  
  1051.